home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’90 / Busy Box / Sources / randomDot2.c < prev   
Encoding:
C/C++ Source or Header  |  1990-06-14  |  909 b   |  43 lines  |  [TEXT/KAHL]

  1. /* file: RandomDot.c    
  2.     puts random dots in its area
  3.     By MGD
  4. */
  5.  
  6. #include "busybox.h"
  7. #define abs(x)    ((x <= 0) ? (-x) : (x))
  8.  
  9.  
  10. /* Guys: It's possible to put some "file-global" data here if you want to share it
  11.         among all the functions in this file.  It's up to you if you want     */
  12. static Rect    ourRect;
  13.  
  14.  
  15. void InitRandomDot2Obj(Rect *drawArea, int16 ID)    {
  16.     /* You can put various stuffages here - i.e. load string resources, init a brick
  17.         picture, oop ack.    */
  18.     
  19.     ourRect = *drawArea;
  20.     
  21. }    /* InitRandomDotObj    */
  22.  
  23.  
  24.  
  25. void DrawRandomDot2Obj(int16 ID)    {
  26.     static Point whereLast;    /* what the last point drawn was    */
  27.     
  28.     int16    i, j, width, height, z;
  29.     
  30.     MoveTo(whereLast.h, whereLast.v);
  31.     width = ourRect.right - ourRect.left;
  32.     height = ourRect.bottom - ourRect.top;
  33.     z = Random();
  34.     i = abs(z) % width;
  35.     z = Random();
  36.     j = abs(z) % height;
  37.     LineTo(i,j);
  38.     whereLast.h = i; whereLast.v = j;
  39. }    /* DrawRandomDotObj    */
  40.  
  41.  
  42.  
  43.